package com.cfpamf.ms.insur.pay.job;

import com.cfpamf.ms.insur.pay.dao.PayOrderMapper;
import com.cfpamf.ms.insur.pay.pojo.po.PayOrderPO;
import com.cfpamf.ms.insur.pay.service.InsurNotifyService;
import com.cfpamf.ms.insur.pay.util.XxlLogger;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 通知业务系统补偿
 *
 * @author zhangnayi
 */
@Slf4j
@Component
@JobHandler(value = "notify-make-up")
public class BizSysNotifyMakeUpJobHandler extends IJobHandler {

    @Autowired
    private InsurNotifyService insurNotifyService;

    @Autowired
    private PayOrderMapper payOrderMapper;

    @Override
    public ReturnT<String> execute(String s) throws Exception {
        XxlLogger.info(log, "=============通知业务系统补偿 start==============");
        List<PayOrderPO> payOrderList = payOrderMapper.selectUnNotifyBizSysPayOrderList();
        payOrderList.forEach(payOrder -> {
            try {
                XxlLogger.info(log, String.format("通知业务系统补偿 orderNo=%s", payOrder.getOrderNo()));
                insurNotifyService.sourceSysPayCallbackNotify(payOrder.getOrderNo());
            } catch (Exception e) {
                XxlLogger.error(log, e);
            }
        });
        XxlLogger.info(log, "=============通知业务系统补偿 end================");
        return ReturnT.SUCCESS;
    }
}
